package icu.qx.pbs.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.domain.SysUser;
import icu.qx.pbs.feign.SysUserFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import icu.qx.pbs.domain.PbsWorkGroupPeo;
import icu.qx.pbs.service.IPbsWorkGroupPeoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 生产班组成员Controller
 *
 * @author yong
 * @date 2024-07-03
 */
@RestController
@RequestMapping("/pbs/workGroupPeo")
public class PbsWorkGroupPeoController extends BaseController {
    @Autowired
    private IPbsWorkGroupPeoService pbsWorkGroupPeoService;
    @Autowired
    private SysUserFeign sysUserFeign;

    /**
     * 查询生产班组成员列表
     */
    @GetMapping("/list")
    public AjaxResult list(PbsWorkGroupPeo pbsWorkGroupPeo) {
        List<PbsWorkGroupPeo> list = pbsWorkGroupPeoService.selectPbsWorkGroupPeoList(pbsWorkGroupPeo);
        list.forEach(e -> {
            R<SysUser> userR = sysUserFeign.username(e.getWgroupPeo());
            e.setWgroupPeoName(userR.getData().getUserName());
        });
        return success(list);
    }

    /**
     * 导出生产班组成员列表
     */
    @Log(title = "生产班组成员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PbsWorkGroupPeo pbsWorkGroupPeo) {
        List<PbsWorkGroupPeo> list = pbsWorkGroupPeoService.selectPbsWorkGroupPeoList(pbsWorkGroupPeo);
        ExcelUtil<PbsWorkGroupPeo> util = new ExcelUtil<PbsWorkGroupPeo>(PbsWorkGroupPeo.class);
        util.exportExcel(response, list, "生产班组成员数据");
    }

    /**
     * 新增生产班组成员
     */
    @Log(title = "生产班组成员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PbsWorkGroupPeo pbsWorkGroupPeo) {
        return toAjax(pbsWorkGroupPeoService.insertPbsWorkGroupPeo(pbsWorkGroupPeo));
    }

    /**
     * 修改生产班组成员
     */
    @Log(title = "生产班组成员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PbsWorkGroupPeo pbsWorkGroupPeo) {
        return toAjax(pbsWorkGroupPeoService.updatePbsWorkGroupPeo(pbsWorkGroupPeo));
    }

    /**
     * 删除生产班组成员
     */
    @Log(title = "生产班组成员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{wgroupIds}")
    public AjaxResult remove(@PathVariable Long[] wgroupIds) {
        return toAjax(pbsWorkGroupPeoService.deletePbsWorkGroupPeoByWgroupIds(wgroupIds));
    }
}
